package com.xmall.controller.admin;

import com.xmall.bean.vo.BaseRespVo;
import com.xmall.bean.table.Coupon;
import com.xmall.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    private CouponService couponService;

    @RequestMapping("list")
    public BaseRespVo list(@RequestParam Map<String, String> params){
        //todo
        Map<String, Object> result = couponService.queryList(params);
        return BaseRespVo.ok(result);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Coupon coupon){
        coupon = couponService.createCoupon(coupon);
        return BaseRespVo.ok(coupon);
    }

    @RequestMapping("read")
    public BaseRespVo read(@RequestParam Integer id){
        Coupon coupon = couponService.selectById(id);
        return BaseRespVo.ok(coupon);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Coupon update){
        update = couponService.updateCoupon(update);
        return BaseRespVo.ok(update);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Coupon delete){
        couponService.deleteCoupon(delete);
        return BaseRespVo.ok();
    }

    @RequestMapping("listuser")
    public BaseRespVo listuser(@RequestParam Map<String, String> params){
        Map<String, Object> result = couponService.queryListUser(params);
        return BaseRespVo.ok(result);
    }
}
